package com.larosa.practice.domain;

import com.larosa.practice.fruitenum.Fruit;
import com.larosa.practice.strategy.PricingStrategy;

import java.math.BigDecimal;

/**
 * @Author: larosa
 * @Description: 超市类，负责管理水果销售和价格计算
 * @DateTime: 2025/2/9 8:12
 **/
public class Supermarket {
    /**
     * 价格策略
     */
    private PricingStrategy pricingStrategy;

    public Supermarket(PricingStrategy pricingStrategy) {
        this.pricingStrategy = pricingStrategy;
    }
    public void setPricingStrategy(PricingStrategy pricingStrategy) {
        this.pricingStrategy = pricingStrategy;
    }

    /**
     * 计算购买水果的花费
     * @param appleQuantity 苹果的重量
     * @param strawberryQuantity 草莓的重量
     * @param mangoQuantity  芒果的重量
     * @return
     */
    public BigDecimal calculateTotalPrice(int appleQuantity, int strawberryQuantity, int mangoQuantity) {
        return pricingStrategy.calculateTotalPrice(appleQuantity, strawberryQuantity, mangoQuantity);
    }

    /**
     *动态调整价格
     * @param fruit
     * @param price 价格
     */
    public void setFruitPrice(Fruit fruit, BigDecimal price) {
        fruit.setPrice(price);
    }
}
